package com.atguigu.yygh.order.controller;

import com.atguigu.yygh.common.result.Result;
import com.atguigu.yygh.enums.OrderStatusEnum;
import com.atguigu.yygh.model.order.OrderInfo;
import com.atguigu.yygh.order.service.OrderInfoService;
import com.atguigu.yygh.vo.order.OrderQueryVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api(tags = "订单预约接口")
@RestController
@RequestMapping("/api/order/orderInfo")
public class ApiOrderInfoController {
    @Autowired
    private OrderInfoService orderInfoService;

    @ApiOperation("提交新增订单")
    @PostMapping("auth/submitOrderInfo/{scheduleId/{patientId}")
    public Result submitOrderInfo(@PathVariable("scheduleId") String scheduleId,
                                  @PathVariable("patientId") Long patientId) {

        Long resultOrderInfo = orderInfoService.createOrderInfo(scheduleId, patientId);

        return Result.ok(resultOrderInfo);

    }


    @ApiOperation("订单列表加分页查询")
    @PostMapping("auth/findPage/{page}/{limit}")
    public Result findPageOrderInfo(@PathVariable("page") Long page,
                                    @PathVariable("limit") Long limit,
                                    OrderQueryVo orderQueryVo) {
        Page<OrderInfo> pageParams = new Page<>(page, limit);
        IPage<OrderInfo> orderInfoIPageModel = orderInfoService.selectPage(pageParams, orderQueryVo);
        return Result.ok(orderInfoIPageModel);
    }

    @ApiOperation("根据id查询订单")
    @PostMapping("auth/getOrderInfo/{orderInfoId}")
    public Result getOrderInfo(@PathVariable("orderInfoId") Long orderInfoId) {
        OrderInfo orderInfo = orderInfoService.getOrderInfoById(orderInfoId);
        return Result.ok(orderInfo);
    }

    @ApiOperation("查询订单状态")
    @PostMapping("auth/getOrderStatus")
    public Result getOrderStatus() {
        return Result.ok(OrderStatusEnum.getStatusList());
    }


}
